package com.wits.platform.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.wits.platform.dao.TabDDao;
import com.wits.platform.dao.TabHDao;
import com.wits.platform.entity.TabD;
import com.wits.platform.entity.TabDPK;
import com.wits.platform.entity.TabH;

@Component
public class TabService extends BaseService<TabH,String>{

	@Resource
	private TabDDao tabDDao;
	
	private TabHDao tabHDao;
	
	@Resource
	public void setTabHDao(TabHDao tabHDao) {
		this.baseDao=tabHDao;
		this.tabHDao = tabHDao;
	}



	public List<TabD> findTabDByThId(String thId) {
		return tabDDao.findTabDByThId(thId);
	}

	public void save(TabH command, List<TabD> tabDList) {
		tabHDao.save(command);
		tabDDao.executeUpdate("delete from TabD where id.thId=?1",command.getThId());
		for(TabD tabD : tabDList){
			tabD.setId(new TabDPK(command.getThId(),tabD.getTdId()));
		}
		tabDDao.save(tabDList);
	}

	@Override
	public void deleteInBatch(List<String> idList) {
		tabDDao.executeUpdate("delete from TabD where id.thId in(?1)",idList);
		tabHDao.executeUpdate("delete from TabH where thId in(?1)", idList);
	}
	
}
